package com.linys.scala.qf.day03

import scala.collection.mutable.ArrayBuffer

/**
  * Created by admin on 2019/10/22.
  */
object SingletonDemo {
  def main(args: Array[String]): Unit = {
    val s = SessionFactory
    println(s.getSession)
    println(s.getSession.size)
    println(s.removeSession)
    println(s.getSession)
    println(s.getSession.size)
  }
}

object SessionFactory {
  println("SessionFactory被执行了！")
  var i = 5
  val sessions = new ArrayBuffer[Session]()
  while(i > 0){
    println("while 执行！")
    sessions.append(new Session)
    i -= 1
  }

  def getSession: ArrayBuffer[Session] = sessions

  def removeSession(): Session = {
    val session = sessions(0)
    sessions.remove(0)
    return session
  }

}

class Session{}
